package org.jeecg.modules.inspect.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.inspect.entity.*;
import org.jeecg.modules.inspect.service.*;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

 /**
 * @Description: 班次管理
 * @Author: jeecg-boot
 * @Date:   2024-03-10
 * @Version: V1.0
 */
@Api(tags="班次管理")
@RestController
@RequestMapping("/inspect/insClasses")
@Slf4j
public class InsClassesController extends JeecgController<InsClasses, IInsClassesService> {

	@Autowired
	private IInsClassesService insClassesService;

	@Autowired
	private IInsClassesLineService insClassesLineService;

	@Autowired
	private IInsClassesUserService insClassesUserService;

	@Autowired
	private IInsClassesCommonService insClassesCommonService;

	@Autowired
	private IInsClassesSpecialService insClassesSpecialService;


	/*---------------------------------主表处理-begin-------------------------------------*/

	/**
	 * 分页列表查询
	 * @param insClasses
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "班次管理-分页列表查询")
	@ApiOperation(value="班次管理-分页列表查询", notes="班次管理-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<InsClasses>> queryPageList(InsClasses insClasses,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<InsClasses> queryWrapper = QueryGenerator.initQueryWrapper(insClasses, req.getParameterMap());
		Page<InsClasses> page = new Page<InsClasses>(pageNo, pageSize);
		IPage<InsClasses> pageList = insClassesService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
     *   添加
     * @param insClasses
     * @return
     */
    @AutoLog(value = "班次管理-添加")
    @ApiOperation(value="班次管理-添加", notes="班次管理-添加")
    //@RequiresPermissions("org.jeecg.modules:ins_classes:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody InsClasses insClasses) {
        insClassesService.save(insClasses);
        return Result.OK("添加成功！");
    }

    /**
     *  编辑
     * @param insClasses
     * @return
     */
    @AutoLog(value = "班次管理-编辑")
    @ApiOperation(value="班次管理-编辑", notes="班次管理-编辑")
    //@RequiresPermissions("org.jeecg.modules:ins_classes:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> edit(@RequestBody InsClasses insClasses) {
        insClassesService.updateById(insClasses);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     * @param id
     * @return
     */
    @AutoLog(value = "班次管理-通过id删除")
    @ApiOperation(value="班次管理-通过id删除", notes="班次管理-通过id删除")
    //@RequiresPermissions("org.jeecg.modules:ins_classes:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name="id",required=true) String id) {
        insClassesService.delMain(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @AutoLog(value = "班次管理-批量删除")
    @ApiOperation(value="班次管理-批量删除", notes="班次管理-批量删除")
    //@RequiresPermissions("org.jeecg.modules:ins_classes:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        this.insClassesService.delBatchMain(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 导出
     * @return
     */
    //@RequiresPermissions("org.jeecg.modules:ins_classes:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, InsClasses insClasses) {
        return super.exportXls(request, insClasses, InsClasses.class, "班次管理");
    }

    /**
     * 导入
     * @return
     */
    //@RequiresPermissions("org.jeecg.modules:ins_classes:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, InsClasses.class);
    }
	/*---------------------------------主表处理-end-------------------------------------*/
	

    /*--------------------------------子表处理-线路配置-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	//@AutoLog(value = "线路配置-通过主表ID查询")
	@ApiOperation(value="线路配置-通过主表ID查询", notes="线路配置-通过主表ID查询")
	@GetMapping(value = "/listInsClassesLineByMainId")
    public Result<IPage<InsClassesLine>> listInsClassesLineByMainId(InsClassesLine insClassesLine,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<InsClassesLine> queryWrapper = QueryGenerator.initQueryWrapper(insClassesLine, req.getParameterMap());
        Page<InsClassesLine> page = new Page<InsClassesLine>(pageNo, pageSize);
        IPage<InsClassesLine> pageList = insClassesLineService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param insClassesLine
	 * @return
	 */
	@AutoLog(value = "线路配置-添加")
	@ApiOperation(value="线路配置-添加", notes="线路配置-添加")
	@PostMapping(value = "/addInsClassesLine")
	public Result<String> addInsClassesLine(@RequestBody InsClassesLine insClassesLine) {
		insClassesLineService.save(insClassesLine);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param insClassesLine
	 * @return
	 */
	@AutoLog(value = "线路配置-编辑")
	@ApiOperation(value="线路配置-编辑", notes="线路配置-编辑")
	@RequestMapping(value = "/editInsClassesLine", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editInsClassesLine(@RequestBody InsClassesLine insClassesLine) {
		insClassesLineService.updateById(insClassesLine);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "线路配置-通过id删除")
	@ApiOperation(value="线路配置-通过id删除", notes="线路配置-通过id删除")
	@DeleteMapping(value = "/deleteInsClassesLine")
	public Result<String> deleteInsClassesLine(@RequestParam(name="id",required=true) String id) {
		insClassesLineService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "线路配置-批量删除")
	@ApiOperation(value="线路配置-批量删除", notes="线路配置-批量删除")
	@DeleteMapping(value = "/deleteBatchInsClassesLine")
	public Result<String> deleteBatchInsClassesLine(@RequestParam(name="ids",required=true) String ids) {
	    this.insClassesLineService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportInsClassesLine")
    public ModelAndView exportInsClassesLine(HttpServletRequest request, InsClassesLine insClassesLine) {
		 // Step.1 组装查询条件
		 QueryWrapper<InsClassesLine> queryWrapper = QueryGenerator.initQueryWrapper(insClassesLine, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<InsClassesLine> pageList = insClassesLineService.list(queryWrapper);
		 List<InsClassesLine> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, "线路配置");
		 mv.addObject(NormalExcelConstants.CLASS, InsClassesLine.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("线路配置报表", "导出人:" + sysUser.getRealname(), "线路配置"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importInsClassesLine/{mainId}")
    public Result<?> importInsClassesLine(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
			 MultipartFile file = entity.getValue();
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<InsClassesLine> list = ExcelImportUtil.importExcel(file.getInputStream(), InsClassesLine.class, params);
				 for (InsClassesLine temp : list) {
                    temp.setClassId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 insClassesLineService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.OK("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-线路配置-end----------------------------------------------*/

    /*--------------------------------子表处理-班次人员-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	//@AutoLog(value = "班次人员-通过主表ID查询")
	@ApiOperation(value="班次人员-通过主表ID查询", notes="班次人员-通过主表ID查询")
	@GetMapping(value = "/listInsClassesUserByMainId")
    public Result<IPage<InsClassesUser>> listInsClassesUserByMainId(InsClassesUser insClassesUser,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<InsClassesUser> queryWrapper = QueryGenerator.initQueryWrapper(insClassesUser, req.getParameterMap());
        Page<InsClassesUser> page = new Page<InsClassesUser>(pageNo, pageSize);
        IPage<InsClassesUser> pageList = insClassesUserService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param insClassesUser
	 * @return
	 */
	@AutoLog(value = "班次人员-添加")
	@ApiOperation(value="班次人员-添加", notes="班次人员-添加")
	@PostMapping(value = "/addInsClassesUser")
	public Result<String> addInsClassesUser(@RequestBody InsClassesUser insClassesUser) {
		insClassesUserService.save(insClassesUser);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param insClassesUser
	 * @return
	 */
	@AutoLog(value = "班次人员-编辑")
	@ApiOperation(value="班次人员-编辑", notes="班次人员-编辑")
	@RequestMapping(value = "/editInsClassesUser", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editInsClassesUser(@RequestBody InsClassesUser insClassesUser) {
		insClassesUserService.updateById(insClassesUser);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "班次人员-通过id删除")
	@ApiOperation(value="班次人员-通过id删除", notes="班次人员-通过id删除")
	@DeleteMapping(value = "/deleteInsClassesUser")
	public Result<String> deleteInsClassesUser(@RequestParam(name="id",required=true) String id) {
		insClassesUserService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "班次人员-批量删除")
	@ApiOperation(value="班次人员-批量删除", notes="班次人员-批量删除")
	@DeleteMapping(value = "/deleteBatchInsClassesUser")
	public Result<String> deleteBatchInsClassesUser(@RequestParam(name="ids",required=true) String ids) {
	    this.insClassesUserService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportInsClassesUser")
    public ModelAndView exportInsClassesUser(HttpServletRequest request, InsClassesUser insClassesUser) {
		 // Step.1 组装查询条件
		 QueryWrapper<InsClassesUser> queryWrapper = QueryGenerator.initQueryWrapper(insClassesUser, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<InsClassesUser> pageList = insClassesUserService.list(queryWrapper);
		 List<InsClassesUser> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, "班次人员");
		 mv.addObject(NormalExcelConstants.CLASS, InsClassesUser.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("班次人员报表", "导出人:" + sysUser.getRealname(), "班次人员"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importInsClassesUser/{mainId}")
    public Result<?> importInsClassesUser(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
			 MultipartFile file = entity.getValue();
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<InsClassesUser> list = ExcelImportUtil.importExcel(file.getInputStream(), InsClassesUser.class, params);
				 for (InsClassesUser temp : list) {
                    temp.setClassId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 insClassesUserService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.OK("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-班次人员-end----------------------------------------------*/

    /*--------------------------------子表处理-正常日期-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	//@AutoLog(value = "正常日期-通过主表ID查询")
	@ApiOperation(value="正常日期-通过主表ID查询", notes="正常日期-通过主表ID查询")
	@GetMapping(value = "/listInsClassesCommonByMainId")
    public Result<IPage<InsClassesCommon>> listInsClassesCommonByMainId(InsClassesCommon insClassesCommon,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<InsClassesCommon> queryWrapper = QueryGenerator.initQueryWrapper(insClassesCommon, req.getParameterMap());
        Page<InsClassesCommon> page = new Page<InsClassesCommon>(pageNo, pageSize);
        IPage<InsClassesCommon> pageList = insClassesCommonService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param insClassesCommon
	 * @return
	 */
	@AutoLog(value = "正常日期-添加")
	@ApiOperation(value="正常日期-添加", notes="正常日期-添加")
	@PostMapping(value = "/addInsClassesCommon")
	public Result<String> addInsClassesCommon(@RequestBody InsClassesCommon insClassesCommon) {
		insClassesCommonService.save(insClassesCommon);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param insClassesCommon
	 * @return
	 */
	@AutoLog(value = "正常日期-编辑")
	@ApiOperation(value="正常日期-编辑", notes="正常日期-编辑")
	@RequestMapping(value = "/editInsClassesCommon", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editInsClassesCommon(@RequestBody InsClassesCommon insClassesCommon) {
		insClassesCommonService.updateById(insClassesCommon);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "正常日期-通过id删除")
	@ApiOperation(value="正常日期-通过id删除", notes="正常日期-通过id删除")
	@DeleteMapping(value = "/deleteInsClassesCommon")
	public Result<String> deleteInsClassesCommon(@RequestParam(name="id",required=true) String id) {
		insClassesCommonService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "正常日期-批量删除")
	@ApiOperation(value="正常日期-批量删除", notes="正常日期-批量删除")
	@DeleteMapping(value = "/deleteBatchInsClassesCommon")
	public Result<String> deleteBatchInsClassesCommon(@RequestParam(name="ids",required=true) String ids) {
	    this.insClassesCommonService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportInsClassesCommon")
    public ModelAndView exportInsClassesCommon(HttpServletRequest request, InsClassesCommon insClassesCommon) {
		 // Step.1 组装查询条件
		 QueryWrapper<InsClassesCommon> queryWrapper = QueryGenerator.initQueryWrapper(insClassesCommon, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<InsClassesCommon> pageList = insClassesCommonService.list(queryWrapper);
		 List<InsClassesCommon> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, "正常日期");
		 mv.addObject(NormalExcelConstants.CLASS, InsClassesCommon.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("正常日期报表", "导出人:" + sysUser.getRealname(), "正常日期"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importInsClassesCommon/{mainId}")
    public Result<?> importInsClassesCommon(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
			 MultipartFile file = entity.getValue();
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<InsClassesCommon> list = ExcelImportUtil.importExcel(file.getInputStream(), InsClassesCommon.class, params);
				 for (InsClassesCommon temp : list) {
                    temp.setClassId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 insClassesCommonService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.OK("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-正常日期-end----------------------------------------------*/

    /*--------------------------------子表处理-特殊日期-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	//@AutoLog(value = "特殊日期-通过主表ID查询")
	@ApiOperation(value="特殊日期-通过主表ID查询", notes="特殊日期-通过主表ID查询")
	@GetMapping(value = "/listInsClassesSpecialByMainId")
    public Result<IPage<InsClassesSpecial>> listInsClassesSpecialByMainId(InsClassesSpecial insClassesSpecial,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<InsClassesSpecial> queryWrapper = QueryGenerator.initQueryWrapper(insClassesSpecial, req.getParameterMap());
        Page<InsClassesSpecial> page = new Page<InsClassesSpecial>(pageNo, pageSize);
        IPage<InsClassesSpecial> pageList = insClassesSpecialService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param insClassesSpecial
	 * @return
	 */
	@AutoLog(value = "特殊日期-添加")
	@ApiOperation(value="特殊日期-添加", notes="特殊日期-添加")
	@PostMapping(value = "/addInsClassesSpecial")
	public Result<String> addInsClassesSpecial(@RequestBody InsClassesSpecial insClassesSpecial) {
		insClassesSpecialService.save(insClassesSpecial);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param insClassesSpecial
	 * @return
	 */
	@AutoLog(value = "特殊日期-编辑")
	@ApiOperation(value="特殊日期-编辑", notes="特殊日期-编辑")
	@RequestMapping(value = "/editInsClassesSpecial", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editInsClassesSpecial(@RequestBody InsClassesSpecial insClassesSpecial) {
		insClassesSpecialService.updateById(insClassesSpecial);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "特殊日期-通过id删除")
	@ApiOperation(value="特殊日期-通过id删除", notes="特殊日期-通过id删除")
	@DeleteMapping(value = "/deleteInsClassesSpecial")
	public Result<String> deleteInsClassesSpecial(@RequestParam(name="id",required=true) String id) {
		insClassesSpecialService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "特殊日期-批量删除")
	@ApiOperation(value="特殊日期-批量删除", notes="特殊日期-批量删除")
	@DeleteMapping(value = "/deleteBatchInsClassesSpecial")
	public Result<String> deleteBatchInsClassesSpecial(@RequestParam(name="ids",required=true) String ids) {
	    this.insClassesSpecialService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportInsClassesSpecial")
    public ModelAndView exportInsClassesSpecial(HttpServletRequest request, InsClassesSpecial insClassesSpecial) {
		 // Step.1 组装查询条件
		 QueryWrapper<InsClassesSpecial> queryWrapper = QueryGenerator.initQueryWrapper(insClassesSpecial, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<InsClassesSpecial> pageList = insClassesSpecialService.list(queryWrapper);
		 List<InsClassesSpecial> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, "特殊日期");
		 mv.addObject(NormalExcelConstants.CLASS, InsClassesSpecial.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("特殊日期报表", "导出人:" + sysUser.getRealname(), "特殊日期"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importInsClassesSpecial/{mainId}")
    public Result<?> importInsClassesSpecial(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
			 MultipartFile file = entity.getValue();
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<InsClassesSpecial> list = ExcelImportUtil.importExcel(file.getInputStream(), InsClassesSpecial.class, params);
				 for (InsClassesSpecial temp : list) {
                    temp.setClassId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 insClassesSpecialService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.OK("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-特殊日期-end----------------------------------------------*/

	 @Autowired
	 private RedisUtil redisUtil;
	 /**
	  * 获取指定日期是否是节假日标识
	  * @return
	  */
	 @RequestMapping(value = "/getIsNotWork")
	 @ResponseBody
	 public String getIsNotWork( @RequestParam("data") String data) {
		 Object isnotwork = redisUtil.get(data + "_isnotwork");
		 return Objects.isNull(isnotwork)?"0":isnotwork.toString();
	 }


}
